package com.cloud.easyexcel.controller;

import com.cloud.easyexcel.service.SysProductBomService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@RestController
public class ExcelController {
    @Resource
    private SysProductBomService sysProductBomService;

    /**
     * BOM模板导出
     **/
    @GetMapping("/excel/template")
    public void downloadTemplate(HttpServletResponse response) {
        sysProductBomService.downloadTemplate(response);
    }

    /**
     * BOM导入
     *
     * @return
     */
    @PostMapping("/excel/import")
    public void importTemplateData(@RequestParam("file") MultipartFile file,
                                   @RequestParam("versionId") Integer versionId) {
        sysProductBomService.importTemplateData(file, versionId);
    }

    /**
     * BOM导出
     *
     * @return
     */
    @GetMapping("/excel/export")
    public void export(HttpServletResponse response) throws Exception {
        String export = sysProductBomService.export(response);
    }
}
